from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from Driver.Driver import Blogdriver

class BlogCreat:
    driver=''
    url=''
    def __init__(self):
        self.driver=Blogdriver.driver
        self.url="http://8.137.19.140:9090/blog_edit.html"
    # 未登录进入
    def NoLogIn(self):
        self.driver.get(self.url)
    # 登陆进入
    def LogIn(self):
        self.driver.get(self.url)
    # 有标题有内容发布内容
    # 标题为纯空白字符
    def TitleHasSpace(self):
        self.driver.find_element(By.CSS_SELECTOR,"#title").send_keys("   ")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        Blogdriver.getscreen()
    # 标题不为纯空白字符
    def TitleNoHasSpace(self):
        self.driver.find_element(By.CSS_SELECTOR,"#title").send_keys("6666")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        Blogdriver.getscreen()
    # 无标题发布内容
    def NoTitle(self):
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        alert=WebDriverWait(self.driver,2).until(expected_conditions.alert_is_present())
        alert.accept()
        Blogdriver.getscreen()
    #博客编辑界面博客列表
    # 点击主页
    def titlebarHome(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(4)").click()
        Blogdriver.getscreen()


    # 点击编辑页
    def titlebarCreate(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(5)").click()
        Blogdriver.getscreen()


    # 点击注销
    def titlebarOut(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)").click()
        Blogdriver.getscreen()